package com.woniuxy.intellihome.service.impl;

import com.woniuxy.intellihome.entity.GoodsSpu;
import com.woniuxy.intellihome.entity.Sku;
import com.woniuxy.intellihome.mapper.CategoryMapper;
import com.woniuxy.intellihome.mapper.GoodsSpuMapper;
import com.woniuxy.intellihome.service.GoodsSpuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.intellihome.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
@Service
public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper, GoodsSpu> implements GoodsSpuService {
    @Autowired
    private GoodsSpuMapper goodsSpuMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private SkuService skuService;


    @Override
    public List<GoodsSpu> listByCategory(int categoryId) {
        return goodsSpuMapper.listByCategory(categoryId);
    }

    @Override
    public GoodsSpu getWithCategoryById(int id) {
        GoodsSpu spu = goodsSpuMapper.selectById(id);
        spu.setCategory(categoryMapper.selectById(spu.getCategoryId()));
        return spu;
    }

    /**
     * 得到属于sku的spu实现类
     *
     * @param skuId skuId
     * @return 属于sku的spu
     */
    @Override
    public GoodsSpu getSpcBelong2Sku(int skuId) {
        GoodsSpu spu = goodsSpuMapper.getSpuBelong2Sku(skuId);
        return spu;
    }
}
